package com.njqy.ticket.expression;

import com.njqy.ticket.service.common.IUserService;
import com.njqy.ticket.util.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 权限注解
 */
@Component("ex")
public class AuthExpressionRoot {

    @Autowired
    private IUserService userService;

    public boolean hasAuthority(String authority){
        if(StringUtils.isBlank(authority)){
            return false;
        }
        List<String> permissionList = userService.getPermissionList(CommonUtil.getUserName());
        if(!CollectionUtils.isEmpty(permissionList) && permissionList.contains(authority)){
            return true;
        }
        return false;
    }

}
